package cn.kbyue.security.security;


import cn.kbyue.security.utils.BizExceptionEnum;
import cn.kbyue.security.utils.Result;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

/**
 * 用户未登录处理类
 *
 * @author xl
 * @date 2020/4/19 15:00
 */
@Slf4j
@Component
public class CustomAuthenticationEntryPoint implements AuthenticationEntryPoint {

    /**
     * 用户未登录的返回
     */
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException {
        Result.responseResult(response, Result.error(BizExceptionEnum.Unauthorized));
    }
}
